package main;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

class DialogBoxSuccessOrNot2 extends JDialog{
	private static final long serialVersionUID = 1L;
	private JLabel label;
	private JButton ok;
	private Container cp;
	
	public DialogBoxSuccessOrNot2() {
		
		label=new JLabel("Sucesso ou nao");
		ok=new JButton("OK");
		
		
		label.setBounds(5, 5, 200, 100);
		ok.setBounds(140, 105, 100, 30);
		cp=getContentPane();
		cp.add(label);
		cp.add(ok);
		setLayout(null);
		setSize(400, 200);
		centrarDialogBox();
		setVisible(true);
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		
	}
	
	private void centrarDialogBox(){
		// * colocar sempre a dialogBox no centro do ecra *
		// tamanho do ecra
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		 
		// determinar a nova localizacao da janela
		int w = this.getSize().width;
		int h = this.getSize().height;
		int x = (dim.width-w)/2;
		int y = (dim.height-h)/2;
		 
		// move a janela
		this.setLocation(x, y);
	}

}